var _util = require("../we7/resource/js/util.js"), _util2 = _interopRequireDefault(_util);

function _interopRequireDefault(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

var request = function() {
    var n = 0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : {}, o = 1 < arguments.length && void 0 !== arguments[1] ? arguments[1] : function() {}, t = 2 < arguments.length && void 0 !== arguments[2] ? arguments[2] : function(t) {}, e = 3 < arguments.length && void 0 !== arguments[3] ? arguments[3] : function() {}, i = 4 < arguments.length && void 0 !== arguments[4] ? arguments[4] : "", u = 5 < arguments.length && void 0 !== arguments[5] && arguments[5], a = 6 < arguments.length && void 0 !== arguments[6] ? arguments[6] : "entry/wxapp/distribute";
    "" === i && (i = "GET"), n.version = "2.0.38", _util2.default.request({
        showLoading: u,
        url: a,
        data: n,
        method: i,
        success: function(t) {
            var e = t.data;
            return -1 == e.status ? (login(n, o), !1) : 0 == e.status ? (wx.showModal({
                title: "提示",
                mask: !0,
                content: e.info,
                showCancel: !1
            }), !1) : void o(e);
        },
        fail: t,
        complete: e
    });
}, _post = function(t) {
    var e = 1 < arguments.length && void 0 !== arguments[1] ? arguments[1] : {}, n = 2 < arguments.length && void 0 !== arguments[2] ? arguments[2] : function() {}, o = 3 < arguments.length && void 0 !== arguments[3] ? arguments[3] : function() {}, i = 4 < arguments.length && void 0 !== arguments[4] ? arguments[4] : function() {};
    5 < arguments.length && void 0 !== arguments[5] && arguments[5];
    return request(e, n, o, i, "POST");
}, login = function(n, o) {
    wx.login({
        success: function(t) {
            void 0 === n && (n = {});
            var e = wx.getStorageSync("parent_id") || "";
            request({
                code: t.code,
                parent_id: e,
                contr: "noLogin",
                action: "login"
            }, function(t) {
                wx.setStorageSync("token", t.info), n.token = t.info, request(n, o, function() {}, function() {}, function() {}, "");
            });
        }
    });
}, userinfo = function() {}, upload = function(t) {
    var n = 1 < arguments.length && void 0 !== arguments[1] ? arguments[1] : function(t) {}, e = 2 < arguments.length && void 0 !== arguments[2] ? arguments[2] : "image", o = _util2.default.url("entry/wxapp/distribute"), i = getCurrentPages();
    i.length && (i = i[getCurrentPages().length - 1]) && i.__route__ && (o = o + "&m=" + i.__route__.split("/")[0]), 
    wx.uploadFile({
        url: o,
        filePath: t,
        name: "file",
        header: {},
        formData: {
            contr: "noLogin",
            action: "upload",
            type: e
        },
        success: function(t) {
            var e = JSON.parse(t.data);
            n(e);
        },
        fail: function(t) {
            wx.hideLoading(), getApp().showToast("上传失败");
        }
    });
}, showNotice = function(t) {
    wx.showToast({
        title: t,
        mask: !0,
        image: "../../images/notice.png",
        duration: 2e3
    });
};

module.exports = {
    request: request,
    post: _post,
    upload: upload,
    showNotice: showNotice
};